package com.zj.HJ;

import java.util.*;
import java.util.stream.Collectors;

public class HJ24 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
//        int num = Integer.parseInt(sc.nextLine());
//        String input=sc.nextLine();
//        System.out.println(getRes(input.split(" ")));
        int[] arr = {5, 6, 1, 2, 7, 3, 4, 8};
        System.out.println(getLongIncrease(arr, 0, 7));
    }

    //186 186 150 200 160 130 197 200
    public static int getRes(String[] arr) {
        Integer[] nums = Arrays.asList(arr).stream().map(Integer::parseInt).collect(Collectors.toList()).toArray(new Integer[0]);
        for (int i = 1; i < nums.length - 1; i++) {
            for (int j = 0; j < nums.length && j != i; j++) {
                if (j < i) {
                } else {

                }
            }

        }
        return 0;
    }

    public static int getLongIncrease(int[] arr, int start, int end) {
        Stack<Integer>[] dlist = new Stack[end - start];
        dlist[0] = new Stack<>();
        dlist[0].push(arr[start]);

        int len = 0;
        int index = 1, cur = 0;
        for (int i = start + 1; i < end; i++) {
            boolean put = false, found = false;
            int diff = Integer.MAX_VALUE;
            for (int j = 0; j < index; j++) {
                if (arr[i] > dlist[j].peek()) {
                    if (arr[i] - dlist[j].peek() < diff) {
                        found = true;
                        diff = arr[i] - dlist[j].peek();
                        cur = j;
                    }
                }
            }
            if (found) {
                dlist[cur].push(arr[i]);
                put = true;
            }
            if (!put) {
                dlist[index++] = new Stack<>();
                dlist[index - 1].push(arr[i]);
            }
        }
        for (int i = 0; i < index; i++) {
            if (dlist[i].size() > len) {
                len = dlist[i].size();
            }
        }
        return len;
    }


}
